/*+**************************************************************************/
/***                                                                      ***/
/***   This file is distributed under a BSD license.                      ***/
/***   See LICENSE.txt for details.                                       ***/
/***                                                                      ***/
/**************************************************************************+*/

asc
{
  cbuffer MCubesMtrlVS : register(c0) : slot vs 0
  {
    row_major float4x4 mvp;     // rotation for light vector (not really needed)
    float4 uvm[3];     // rotation for light vector (not really needed)

    extern void Set(const sViewport &view)
    {
      mvp = view.ModelScreen;
      uvm[0].Init(mvp.i.x,mvp.j.x,mvp.k.x,0);
      uvm[1].Init(mvp.i.y,mvp.j.y,mvp.k.y,0);
      uvm[2].Init(mvp.i.z,mvp.j.z,mvp.k.z,0);
    }
  };  
}

/****************************************************************************/

material MCubesMtrl
{
  vs
  {
    asc vs_2_0                 // hlsl code
    {
      use MCubesMtrlVS;
      void main
      (
        in float4 in_pos : POSITION,
        in float3 in_norm : NORMAL,
//        in float4 in_col : COLOR0,
        out float4 out_pos : POSITION,
        out float4 out_col : COLOR0,
        out float3 out_uv0 : TEXCOORD0,
      )
      {
        float3 norm;
        norm.x = dot(in_norm,uvm[0]);
        norm.y = dot(in_norm,uvm[1]);
        norm.z = dot(in_norm,uvm[2]);
        norm = normalize(norm);
        out_uv0 = norm;
        out_col = norm.z*-0.5+0.5;
        out_pos = mul(in_pos,mvp);
      }
    }
  }

  ps
  {
    asc ps_2_0
    {
      sampler2D s0 : register(s0);
      void main
      (
        in float3 uv0 : TEXCOORD0,
        in float4 color : COLOR0,
        out float4 result : COLOR0
      )
      {
        result = color;
        result *= tex2D(s0,normalize(uv0).xy*0.5+0.5);
      }
    }    
  }
};
